package edu.thu.studio.ormdesigner.editor.command;

import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;

import edu.thu.studio.ormdesigner.editor.ORMGraphicalEditor;
import edu.thu.studio.ormdesigner.model.AbstractModel;

public class WithoutUpdateCommand extends Command {
    private CompoundCommand command;
    
    private AbstractModel ormModel;
    
    private ORMGraphicalEditor editor;
    
    public WithoutUpdateCommand(CompoundCommand command, AbstractModel ormModel, ORMGraphicalEditor editor) {
        this.command = command;
        this.ormModel = ormModel;
        this.editor = editor;
    }
    
    @SuppressWarnings("static-access")
    @Override
    public void execute() {
        this.ormModel.setUpdateable(false);
        
        this.editor.getGraphicalViewer().deselectAll();
        
        this.command.execute();
        
        this.ormModel.setUpdateable(true);
        
        this.ormModel.refresh();
    }
    
    @SuppressWarnings("static-access")
    @Override
    public void undo() {
        this.ormModel.setUpdateable(false);
        this.command.undo();
        this.ormModel.setUpdateable(true);
        this.ormModel.refresh();
    }
    
    @Override
    public boolean canExecute() {
        return this.command.canExecute();
    }
    
    @Override
    public boolean canUndo() {
        return this.command.canUndo();
    }
    
}
